// SCENARIO SCRIPT

// This is the special script for your entire scenario. It contains 
// special encounters and code accessable from anywhere in the scenario. it also 
// contains the code that initializes important special things in the 
// scenario (like shops and names and descriptions of special items).

// You can create your own states but you should give all of them numbers greater than // or equal to 10.

beginscenarioscript;

variables;
    int choice;
    int s1 = 0, s2 = 0, s3 = 0, s4 = 0;
    int target;
    int destx, desty;
    int last_abil_time, used = 0;
    int pc, attitude;
body;
beginstate LOAD_SCEN_STATE;
    set_creature_type_level(22, 15);
    set_creature_type_level(23, 16);
    set_creature_type_level(24, 15);
    set_creature_type_level(25, 16);
    set_creature_type_level(26, 17);
    
	init_quest(0, "Return the Earrings", "Sorsha's pet, Stikk the Slug, has swallowed a pair of earrings which belongs to Sorsha. To get them, smash them out of Stikk's stomach (The question is: How?)");
	init_quest(1, "Eliminate Big Spider", "Arghadz-Irhno has asked you to eliminate a weird spider which spits webs everywhere and blocks movement down in Arghadz's basement. (Wonder why the vahnatais can't deal with such a giant spider themselves)");
	init_quest(2, "Return the Wyvern's Best Item", "A wyvern who inhabitated the abandoned naga lair has been mugged (It is as strange as it sounds). You need to get back his/her/its item, an iron-studded, leather toy bat which breathes fire.");
    init_quest(3, "Rid Mine of Ogres", "Janice told you to fight and kill the ogres who invaded the Goldar mines and thus free the people seized by them.");
    init_quest(4, "Find out about the Vahnatai", "Marcus told you to investigate a vahnatai settlement to the east and report if you'd find out anything that has to do with the situation.");
    init_quest(5, "Unlock Orb", "Marcus told you to travel northeast and then south and find the naga, unlock the orb, and hunt down the leader of the movement.");
    init_quest(6, "Return Talisman", "Faradoc told you to go to the cragland of Arachi, hunt down a band of giants, search for a spoon talisman and return it to him.");
    init_quest(7, "Slay Bandits", "You told Jasmine to avenge her parents and kill the band of rogues that slew her parents.");
	init_special_abil(1, "Recharge Orb", 16);
	init_special_item(1, "Goldar Mines Key", "This is a small key, so small that you doubt it is a door that it opens. It was given to you by Janice. She told you you'd need it in the mines.");
	init_special_item(2, "Orb of Nar", "This is a small, orange ellipsoid stone. You can't do anything with it because it is locked.");
	init_special_item(3, "Spoon-Shaped Talisman", "This is a small wooden spoon-shaped object with magical carvings in it. One of the runes is a name. It says: Faradoc");
break;

// This is the state that is called only once at the very beginning of 
// the scenario. Some things that should go here:
//    The stuff in shops. 
//    Creating horses and boats. 
beginstate START_SCEN_STATE; 
       create_boat(0, 5, 24, 7, 1);
       create_boat(1, 7, 4, 30, 1);
       create_boat(2, 9, 5, 41, 1);
       create_boat(3, 9, 5, 40, 1);
       create_boat(4, 16, 5, 40, 0);
       create_boat(5, 4, 5, 33, 0);
       create_horse(0, 6, 7, 40, 1);
       set_flag(1, 1, 200);
// Initialize a few shops. 

// Shop 0 - iron products in Goldar.
add_item_to_shop(0, 31, 4); 
add_item_to_shop(0, 36, 2); 
add_item_to_shop(0, 41, 1); 
add_item_to_shop(0, 46, 2);
add_item_to_shop(0, 51, 4);
add_item_to_shop(0, 56, 2);
add_item_to_shop(0, 61, 1);
add_item_to_shop(0, 86, 20);
add_item_to_shop(0, 122, 4);
add_item_to_shop(0, 127, 3);
add_item_to_shop(0, 132, 1);
add_item_to_shop(0, 142, 4);
add_item_to_shop(0, 324, 2);

// Shop 1 - spore-plants in Alexandra .
add_item_to_shop(1, 5, 25); 
add_item_to_shop(1, 218, 10); 
add_item_to_shop(1, 219, 5); 

// Shop 2 - butcher near Alexandra.
add_item_to_shop(2, 7, 500); 
add_item_to_shop(2, 8, 500); 
add_item_to_shop(2, 10, 30); 
add_item_to_shop(2, 11, 500); 
add_item_to_shop(2, 400, 500); 

// Shop 3 - bakery in Goldar. 
add_item_to_shop(3, 4, 500); 
add_item_to_shop(3, 12, 10); 
add_item_to_shop(3, 399, 10); 
add_item_to_shop(3, 403, 3); 

// Shop 4 - potions.
add_item_to_shop(4, 220, 4); 
add_item_to_shop(4, 221, 3); 
add_item_to_shop(4, 222, 3); 
add_item_to_shop(4, 223, 2);
add_item_to_shop(4, 224, 4); 
add_item_to_shop(4, 225, 3); 
add_item_to_shop(4, 226, 3); 
add_item_to_shop(4, 227, 2);

// Shop 5 - elixir near Alexandra.
add_item_to_shop(5, 228, 4); 
add_item_to_shop(5, 229, 3); 
add_item_to_shop(5, 230, 3); 
add_item_to_shop(5, 231, 2);
add_item_to_shop(5, 232, 3); 
add_item_to_shop(5, 233, 2); 
add_item_to_shop(5, 234, 2); 
add_item_to_shop(5, 235, 2);
add_item_to_shop(5, 395, 2);
add_item_to_shop(5, 396, 2);

// Shop 6 - mage spells in Alexandra.
add_item_to_shop(6, 2000, 6); 
add_item_to_shop(6, 2001, 6);
add_item_to_shop(6, 2002, 6); 
add_item_to_shop(6, 2003, 6);
add_item_to_shop(6, 2004, 5); 
add_item_to_shop(6, 2005, 5);
add_item_to_shop(6, 2006, 4); 
add_item_to_shop(6, 2007, 4);
add_item_to_shop(6, 2008, 3); 
add_item_to_shop(6, 2009, 3);
add_item_to_shop(6, 2010, 3); 
add_item_to_shop(6, 2011, 3);
add_item_to_shop(6, 2012, 3); 
add_item_to_shop(6, 2013, 3);
add_item_to_shop(6, 2014, 3); 
add_item_to_shop(6, 2015, 3);
add_item_to_shop(6, 2016, 3);

// Shop 7 - priest spells.
add_item_to_shop(7, 3000, 6); 
add_item_to_shop(7, 3001, 6);
add_item_to_shop(7, 3002, 6); 
add_item_to_shop(7, 3003, 6);
add_item_to_shop(7, 3004, 5); 
add_item_to_shop(7, 3005, 5);
add_item_to_shop(7, 3006, 5); 
add_item_to_shop(7, 3007, 4);
add_item_to_shop(7, 3008, 4); 
add_item_to_shop(7, 3009, 4);
add_item_to_shop(7, 3010, 3); 
add_item_to_shop(7, 3011, 3);
add_item_to_shop(7, 3012, 3); 
add_item_to_shop(7, 3014, 3); 
add_item_to_shop(7, 3015, 3);
add_item_to_shop(7, 3016, 3);

// Shop 8 - arcane spells in Gherbag.
add_item_to_shop(8, 2017, 3);
add_item_to_shop(8, 2018, 3);
add_item_to_shop(8, 2019, 3);

// Shop 9 - divine spells.
add_item_to_shop(9, 3013, 3);
add_item_to_shop(9, 3017, 3);
add_item_to_shop(9, 3018, 3);
add_item_to_shop(9, 3019, 3);

// Shop 10 - brew in Alexandra.
add_item_to_shop(10, 236, 1);
add_item_to_shop(10, 237, 1);
add_item_to_shop(10, 238, 1);
add_item_to_shop(10, 239, 1);
add_item_to_shop(10, 240, 1);
add_item_to_shop(10, 241, 1);
add_item_to_shop(10, 242, 1);
add_item_to_shop(10, 243, 1);

// Shop 11 - scrolls.
add_item_to_shop(11, 244, 3);
add_item_to_shop(11, 245, 3);
add_item_to_shop(11, 246, 3);
add_item_to_shop(11, 247, 3);
add_item_to_shop(11, 248, 3);
add_item_to_shop(11, 249, 3);
add_item_to_shop(11, 250, 3);
add_item_to_shop(11, 251, 3);
add_item_to_shop(11, 252, 3);
add_item_to_shop(11, 253, 3);
add_item_to_shop(11, 254, 3);
add_item_to_shop(11, 255, 3);
add_item_to_shop(11, 256, 3);
add_item_to_shop(11, 257, 3);
add_item_to_shop(11, 258, 3);
add_item_to_shop(11, 259, 3);
add_item_to_shop(11, 260, 3);
add_item_to_shop(11, 261, 3);

// Shop 12 - leather supply in Alexandra.
add_item_to_shop(12, 25, 8);
add_item_to_shop(12, 26, 4);
add_item_to_shop(12, 27, 2);
add_item_to_shop(12, 111, 8);
add_item_to_shop(12, 113, 4);
add_item_to_shop(12, 136, 2);
add_item_to_shop(12, 137, 2);
add_item_to_shop(12, 138, 2);
add_item_to_shop(12, 146, 2);
add_item_to_shop(12, 314, 2);
add_item_to_shop(12, 315, 1);
add_item_to_shop(12, 321, 3);

// Shop 13 - Store of David Silvercreek.
add_item_to_shop(13, 4002, 1);
add_item_to_shop(13, 4003, 1);
add_item_to_shop(13, 4004, 1);
add_item_to_shop(13, 447, 20);
add_item_to_shop(13, 448, 20);


// Shop 14 - Arnold's Jewelry
add_item_to_shop(14, 167, 4);
add_item_to_shop(14, 207, 8);
add_item_to_shop(14, 210, 2);
add_item_to_shop(14, 212, 1);
add_item_to_shop(14, 464, 4);

// Shop 15 - Bob's "Smithy"
add_item_to_shop(15, 105, 4);
add_item_to_shop(15, 100, 8);
add_item_to_shop(15, 50, 2);
add_item_to_shop(15, 35, 1);
add_item_to_shop(15, 45, 4);

// Shop 16 - Weapon training in Alexandra
add_item_to_shop(16, 5020, 10);
add_item_to_shop(16, 5021, 10);

// Shop 17 - Magery training in Alexandra
add_item_to_shop(17, 5011, 20);
add_item_to_shop(17, 5013, 30);
add_item_to_shop(17, 5025, 10);
add_item_to_shop(17, 5027, 10);

// Shop 18 - Food in Alexandra
add_item_to_shop(18, 4, 500); 
add_item_to_shop(18, 12, 10); 
add_item_to_shop(18, 399, 10); 
add_item_to_shop(18, 403, 3); 

// Shop 19 - Avernite foods in Alexandra
add_item_to_shop(19, 5, 100);
add_item_to_shop(19, 10, 100);
add_item_to_shop(19, 11, 100);
add_item_to_shop(19, 12, 10);

// Shop 20 - Vahnatai souvenirs
add_item_to_shop(20, 380, 4);
add_item_to_shop(20, 383, 40);
add_item_to_shop(20, 385, 10);
add_item_to_shop(20, 452, 10);
add_item_to_shop(20, 453, 5);
break;

// This state is called every tick wherever the party is in the scenario. // You can use the set_state
beginstate START_STATE;
break;

// Place your own states below. Give each a number at least 10.
beginstate 10;
       reset_dialog();
       add_dialog_str(0, "- T H E   N A G A - written by David Silvercreek.", 20);
       add_dialog_str(1, "A naga is technically a snake with human head. It is over 20 feet tall, extremely poisonous, and capable of casting rune magic.", 0);
       add_dialog_str(2, "There are two types of naga known. The red one is the bad. It's caste (If not wild) is a gate keeper or a patroller of hell or other evil realms.", 0);
       add_dialog_str(3, "The green one is good. It can drink water without spoiling it with toxic. It's caste is a guardian.", 0);
       add_dialog_str(4, "The green naga Surxa is very well known in the Serpent Delta. Surxa is the guardian of the Orb of Nar, the ultimate weapon of the delta. Surxa is the only one able to unlock it, and you can't be expecting this naga to unlock it for offensive purposes.", 0);
       add_dialog_str(5, "-_How could anything go wrong with such good protection?_    -David", 0);
       run_dialog(0);
break;
beginstate 11;
       reset_dialog();
       add_dialog_str(0, "- HISTORY OF THE NEPHILIM - written by David Silvercreek.", 20);
       add_dialog_str(1, "Many history researchers believe that the nephilim have their origin in the forests of the Isle of Rovan. The Isle of Rovan is at the far southern outskirts of the archipelagoes of Valorim.", 0);
       add_dialog_str(2, "It is not an impossible thought. The rare giant trees that tend to grow nowhere else are excellent places for feline creatures.", 0);
       add_dialog_str(3, "The trees also provide resources for building boats, with which the nephilim may have gotten into the continent. However, all this is just a theory.", 0);
       add_dialog_str(4, "The only sure thing is that now when all nephilim are going extingt in Valorim and the other continents, the Isle of Rovan is the only place where the wild tribes of nephilim are in majority.", 0);
       add_dialog_str(5, "-_However, more new settlers come to Rovan day by day, warriors along with them. I'm afraid that soon we won't be seeing any of our original fierce furry friends anymore._   -David", 0);
       run_dialog(0);
break;
beginstate 13;
    if ((creature_type(who_is_custom_item_target()) == 172) || (creature_type(who_is_custom_item_target()) == 234) || (creature_type(who_is_custom_item_target()) == 244))
    {
        print_str_color("The Overlord and it's friends are immune to metamorphose.", 1);
        end();
    }
    if (used == 5) {
        if (get_custom_abil_uses(-1, 1) == 1)
            {
            change_custom_abil_uses(0, 1, 1);
            change_custom_abil_uses(1, 1, 1);
            change_custom_abil_uses(2, 1, 1);
            change_custom_abil_uses(3, 1, 1);
            }
        play_sound(-57);
        message_dialog("The orb has run out of energy.", "To recharge it, use the ability Recharge Orb.");
        end();
        }
    target = who_is_custom_item_target();
    destx = char_loc_x(target);
    desty = char_loc_y(target);
    attitude = get_attitude(target);
    put_boom_on_char(target, 7, 0);
    put_jagged_zap(char_loc_x(target), char_loc_y(target), char_loc_x(who_used_custom_item()), char_loc_y(who_used_custom_item()), 2);
    reset_dialog();
    add_dialog_str(0, "The Orb of Nar has 4 slots (numbered from 1 to 4). Each slot can store one creature type in it. You can transform foes into creatures you have captured with the orb.", 0);
    add_dialog_str(1, "Capturing a foe doesn't drain a charge. Also, captured foes tend to disappear after a time. Would you like to capture a foe, or would you like to transform a foe to an already captured foe.", 0);
    add_dialog_choice(0, "Capture foe.");
    add_dialog_choice(1, "Transform foe. (Drains a charge)");
    choice = run_dialog(0);
    if (choice == 1)
        set_state_continue(14);
    if (choice == 2)
        set_state_continue(15);
beginstate 14;
        get_text_response("To which slot?");
        check_text_response_match("1");
        if (got_text_match()) {
            if (s1 != 0) {
                reset_dialog();
                add_dialog_str(0, "Warning: there is already a creature in this slot. A new one would override the old creature. Do you wan't to do this anyway?", 0);
                add_dialog_choice(0, "No.");
                add_dialog_choice(1, "Yes.");
                if (run_dialog(0) == 1)
                    set_state_continue(14);
                }
            run_animation_sound(65);
            s1 = creature_type(target);
            print_named_str(target, "has been captured in slot 1.");
            }
        check_text_response_match("2");
        if (got_text_match()) {
            if (s2 != 0) {
                reset_dialog();
                add_dialog_str(0, "Warning: there is already a creature in this slot. A new one would override the old creature. Do you wan't to do this anyway?", 0);
                add_dialog_choice(0, "No.");
                add_dialog_choice(1, "Yes.");
                if (run_dialog(0) == 1)
                    set_state_continue(14);
                }
            run_animation_sound(65);
            s2 = creature_type(target);
            print_named_str(target, "has been captured in slot 2.");
            }
        check_text_response_match("3");
        if (got_text_match()) {
            if (s3 != 0) {
                reset_dialog();
                add_dialog_str(0, "Warning: there is already a creature in this slot. A new one would override the old creature. Do you wan't to do this anyway?", 0);
                add_dialog_choice(0, "No.");
                add_dialog_choice(1, "Yes.");
                if (run_dialog(0) == 1)
                    set_state_continue(14);
                }
            run_animation_sound(65);
            s3 = creature_type(target);
            print_named_str(target, "has been captured in slot 3.");
            }
        check_text_response_match("4");
        if (got_text_match()) {
            if (s4 != 0) {
                reset_dialog();
                add_dialog_str(0, "Warning: there is already a creature in this slot. A new one would override the old creature. Do you wan't to do this anyway?", 0);
                add_dialog_choice(0, "No.");
                add_dialog_choice(1, "Yes.");
                if (run_dialog(0) == 1)
                    set_state_continue(14);
                }
            run_animation_sound(65);
            s4 = creature_type(target);
            print_named_str(target, "has been captured in slot 4.");
            }
break;
beginstate 15;
    
    get_text_response("From which slot?");
    check_text_response_match("1");
    if (got_text_match()) {
        if (s1 == 0) {
            message_dialog("This slot is empty.", "");
            set_state_continue(15);
            }
        run_animation_sound(43);
        kill_char(target, 2, 0);
        take_item_of_class_on_spot(destx, desty, -1);
        put_stain_on_space(destx, desty, -1);
        place_monster(destx, desty, s1, 0);
        print_named_str(target, "has been transformed.");
        set_attitude(char_on_loc(destx, desty), attitude);
        }
    check_text_response_match("2");
    if (got_text_match()) {
        if (s2 == 0) {
            message_dialog("This slot is empty.", "");
            set_state_continue(15);
            }
        run_animation_sound(43);
        kill_char(target, 2, 0);
        take_item_of_class_on_spot(destx, desty, -1);
        put_stain_on_space(destx, desty, -1);
        place_monster(destx, desty, s2, 0);
        print_named_str(target, "has been transformed.");
        set_attitude(char_on_loc(destx, desty), attitude);
        }
    check_text_response_match("3");
    if (got_text_match()) {
        if (s3 == 0) {
            message_dialog("This slot is empty.", "");
            set_state_continue(15);
            }
        run_animation_sound(43);
        kill_char(target, 2, 0);
        take_item_of_class_on_spot(destx, desty, -1);
        put_stain_on_space(destx, desty, -1);
        place_monster(destx, desty, s3, 0);
        print_named_str(target, "has been transformed.");
        set_attitude(char_on_loc(destx, desty), attitude);
        }
    check_text_response_match("4");
    if (got_text_match()) {
        if (s1 == 0) {
            message_dialog("This slot is empty.", "");
            set_state_continue(15);
            }
        run_animation_sound(43);
        kill_char(target, 2, 0);
        take_item_of_class_on_spot(destx, desty, -1);
        put_stain_on_space(destx, desty, -1);
        place_monster(destx, desty, s4, 0);
        print_named_str(target, "has been transformed.");
        set_attitude(char_on_loc(destx, desty), attitude);
        }
    put_effect_on_space(destx, desty, 10, 10, 1);
    run_animation_sound(27);
    used = used + 1;
break;
beginstate 16;
    if (is_combat()) {
        message_dialog("The Orb of Nar has run out of energy. While it's uncharged, the only thing you can do with it is capture creatures.", "You can't recharge it while in combat.");
        end();
        }
    reset_dialog();
    add_dialog_str(1, "You may attempt to recharge the soul crystal (Warning: This will drain a lot of mana from you).", 0);
    add_dialog_choice(0, "Leave.");
    add_dialog_choice(1, "Recharge.");
    choice = run_dialog(0);
    if (choice == 2) {
        pc = get_selected_pc();
        change_custom_abil_uses(0, 1, -1);
        change_custom_abil_uses(1, 1, -1);
        change_custom_abil_uses(2, 1, -1);
        change_custom_abil_uses(3, 1, -1);
        change_char_energy(0, -5000);
        change_char_energy(1, -5000);
        change_char_energy(2, -5000);
        change_char_energy(3, -5000);
        used = 0;
            }
            
    end();
break;    

beginstate 20;
    large_draw_pic_dialog(544, "This is a crude map on a piece of lizard hide parchment.");
break;
beginstate 21;
    large_draw_pic_dialog(540, "This map, as it doesn't look exactly like the land, was clearly drawn by an artist and not a scout.");
break;
beginstate 22;
    large_draw_pic_dialog(542, "This map is an extremely crude look at Serpent Delta. There are some settlements missing from it. However, on the land between Alexandra and Goldar there is one settlement marking which you think shouldn't be there.");
break;
beginstate 23;
    large_draw_pic_dialog(541, "Congratulations! You found my easter egg! Well, what do you think of the image? Isn't it cool? Oh, and please don't tell the others about it.");
break;
beginstate 24;
    message_dialog("You cant ROW to Valorim. You need to go to Nout and take a ship.", "");
    block_entry(1);
break;